<?php
/**
 * ImpSoft Customer Model
 * All functionality for the customer goes in here.
 * 
 * @package ImpSoft
 * @subpackage ImpSoft Models
 * @copyright Luke Visinoni (luke.visinoni@gmail.com)
 * @author Luke Visinoni (luke.visinoni@gmail.com)
 * @license GNU Lesser General Public License
 */
class Customer extends ImpSoft_Db_Table {

    protected $_name = 'customers';
    protected $_primary = 'customer_id';
    protected $_dependentTables = array();
    protected $_rowClass = 'CustomerRow';
    protected $_required = array();
	/**
	 * Add any filters that should be applied to this model when saving
	 */
	public function getFilters() {
	
		$filters = new Q_Filter_Set();
		return $filters;
	
	}
	/**
	 * Add any rules that should be applied to validation when saving
	 */
	public function getRules() {
	
		$rules = with(new Q_Rule_Set())
			->add(new Q_Rule_NotNull(), array('firstname', 'lastname'), 'This is a required field');
		return $rules;
	
	}
	/**
	 * Returns a sortable list for the admin panel
	 */
 	public function getListForAdmin($order = null, $direction = null) {
	
		$order = ($order) ? $order : "lastname";
		$direction = ($direction) ? $direction : "asc";
		$db = $this->getAdapter();
		$select = $db->select()
			->from(array('c' => 'customers'), array('customer_id', 'firstname', 'lastname', 'company'))
			->join(array('u' => 'users'), 'c.user_id = u.user_id', array('username', 'is_active', 'last_login', 'user_role', 'email'))
			->order("$order $direction");
		return $select;
	
	}

}